package com.hyc.myvideo.data.adapter.my.course;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hyc.myvideo.R;
import com.hyc.myvideo.data.adapter.base.BaseListAdapter;
import com.hyc.myvideo.data.api.model.ModelCourse;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 当前课程|已完成课程 适配器
 * @author gyb
 * @version 1.0
 * @created 2017/07/20
 */
public class CourseCurrentAdapter extends BaseListAdapter<ModelCourse> {
    public CourseCurrentAdapter(Context context, List<ModelCourse> objects) {
        super(context, objects);
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            if (getItemViewType(position) == 0) {
                holder = new ViewHolder();
                //无数据展示
                convertView = inflater.inflate(R.layout.adapter_itme_no, parent, false);
                holder.noDataRootLayout = (LinearLayout) convertView.findViewById(R.id.r_no_id);
            } else {
                convertView = inflater.inflate(R.layout.activity_adapter_current_itme, parent, false);
                holder = new ViewHolder(convertView);
            }
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (hasNoData) {
            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(getScreenWidth(), getScreenHeight() * 2 / 3);
            holder.noDataRootLayout.setLayoutParams(lp);
        } else {
           final ModelCourse modelCourse = mDataList.get(position);
            if(modelCourse != null){
                String name = String.format(mContext.getString(R.string.huc_my_course),modelCourse.getDirect_name());
                holder.textViewCourseName.setText(name);

                String Tclass = String.format(mContext.getString(R.string.huc_my_current_class),  modelCourse.getDirect_hour_count());
                holder.textViewClass.setText(Tclass);

                String Last = String.format(mContext.getString(R.string.huc_my_class),modelCourse.getSurplus_count());
                holder.textViewLast.setText(Last);

                String commission = String.format(mContext.getString(R.string.huc_my_money),new java.text.DecimalFormat("0.00").format(modelCourse.getDirect_commission()));
                holder.textViewCommission.setText(commission);
                String manner = "";
                switch (modelCourse.getDirect_charge_state()){
                    case 0:
                        manner = "免费";
                        break;
                    case 1:
                        manner = "VIP";
                        break;
                    case 2:
                        manner = "收费";
                        break;
                }
                holder.textViewWay.setText(manner);

                //String time = DateUtil.StringToString("2017-07-20", DateStyle.YYYY_MM_DD_DDD);
                holder.textViewTime.setText(modelCourse.getDirect_time());
            }
        }
        return convertView;
    }

    public static class ViewHolder {
        public ViewHolder() {
        }
        public ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        LinearLayout noDataRootLayout;
        //课程名称
        @BindView(R.id.current_t_course)TextView textViewCourseName;
        //多少节课
        @BindView(R.id.current_t_class)TextView textViewClass;
        //剩余课时
        @BindView(R.id.current_t_last)TextView textViewLast;
        //佣金
        @BindView(R.id.current_t_commission)TextView textViewCommission;
        //支付方式
        @BindView(R.id.current_t_way)TextView textViewWay;
        //发布时间 xxxx.xx.xx.xx
        @BindView(R.id.current_t_time)TextView textViewTime;
    }
}
